package cn.readjava.controller.user;

import cn.readjava.bean.User;
import cn.readjava.bean.UserOrder;
import cn.readjava.service.UserOrderService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserOrderController {

    @Resource
    private UserOrderService userOrderService;

    @GetMapping("/user/order")
    public String order(Model model) {
        Subject subject = SecurityUtils.getSubject();
        User principal = (User) subject.getPrincipal();
        List<UserOrder> userOrderList = userOrderService.findAllByOrderUserId(principal.getUserId());
        model.addAttribute("userOrderList", userOrderList);
        return "user/user-order";
    }
}
